﻿<UserControl
    x:Class="mPassRT.Controls.PasswordGeneratorControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:passwordGenerator="using:KeePassLib.Cryptography.PasswordGenerator"
    xmlns:converters="using:mPassRT.Converters" xmlns:controls="using:mPassRT.Controls"
    mc:Ignorable="d">

    <UserControl.Resources>
        <Style x:Key="CommonKeyControlStyle" TargetType="FrameworkElement">
            <Setter Property="Margin" Value="10"/>
        </Style>
        <Style x:Key="TextStyle" BasedOn="{StaticResource CommonKeyControlStyle}" TargetType="TextBlock">
            <Setter Property="FontFamily" Value="Segoe UI"/>
            <Setter Property="FontSize" Value="14.667"/>
            <Setter Property="Margin" Value="10,10,10,0"/>
        </Style>
        <Style x:Key="ButtonStyle" BasedOn="{StaticResource CommonKeyControlStyle}" TargetType="FrameworkElement">
            <Setter Property="MinWidth" Value="100"/>
        </Style>
        <Style x:Key="TextBoxStyle" BasedOn="{StaticResource CommonKeyControlStyle}" TargetType="TextBox">
            
        </Style>
        
        <converters:BooleanToVisibilityConverter x:Key="VisibilityConverter"/>
    </UserControl.Resources>

    <Grid HorizontalAlignment="Stretch" VerticalAlignment="Center" Background="#FF52101C">
        <Grid.Transitions>
            <TransitionCollection>
                <RepositionThemeTransition/>
            </TransitionCollection>
        </Grid.Transitions>

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        
        <TextBlock Grid.Row="0" Style="{StaticResource PageSubheaderTextStyle}" HorizontalAlignment="Center" Text="Password Generator"/>
        
        <StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Center">
            <RadioButton Style="{StaticResource CommonKeyControlStyle}" Command="{Binding SetGeneratorTypeCommand}" 
                         Content="Generate using character set" IsChecked="{Binding IsCharSetGenerationEnabled}">
                <RadioButton.CommandParameter>
                    <passwordGenerator:PasswordGeneratorType>CharSet</passwordGenerator:PasswordGeneratorType>
                </RadioButton.CommandParameter>
            </RadioButton>
            <RadioButton Style="{StaticResource CommonKeyControlStyle}" Command="{Binding SetGeneratorTypeCommand}" 
                         Content="Generate using pattern" IsChecked="{Binding IsPatternGenerationEnabled}">
                <RadioButton.CommandParameter>
                    <passwordGenerator:PasswordGeneratorType>Pattern</passwordGenerator:PasswordGeneratorType>
                </RadioButton.CommandParameter>
            </RadioButton>
        </StackPanel>

        <Grid Grid.Row="2" HorizontalAlignment="Center" Visibility="{Binding IsCharSetGenerationEnabled, Converter={StaticResource VisibilityConverter}}">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            
            <Grid Grid.Row="0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                
                <TextBlock Grid.ColumnSpan="2" Style="{StaticResource TextStyle}">Password Length</TextBlock>
                <Slider Grid.Row="1" Style="{StaticResource CommonKeyControlStyle}" Minimum="1" Maximum="50" TickPlacement="None" LargeChange="5" Value="{Binding PasswordLength, Mode=TwoWay}" Height="42"/>
                <TextBlock Grid.Row="1" Grid.Column="1" Style="{StaticResource TextStyle}" Text="{Binding PasswordLength}" HorizontalAlignment="Center" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5" MinWidth="25">
                    <TextBlock.RenderTransform>
                        <CompositeTransform TranslateY="-5"/>
                    </TextBlock.RenderTransform>
                </TextBlock>
            </Grid>
            
            <Grid Grid.Row="1">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                
                <TextBlock Grid.Row="0" Grid.Column="0" Style="{StaticResource TextStyle}" Grid.ColumnSpan="2">Include characters</TextBlock>

                <CheckBox Grid.Row="1" Grid.Column="0" Style="{StaticResource CommonKeyControlStyle}" IsChecked="{Binding IncludeUppercaseLetters, Mode=TwoWay}">Uppercase letters (A, B, C, ...)</CheckBox>
                <CheckBox Grid.Row="2" Grid.Column="0" Style="{StaticResource CommonKeyControlStyle}" IsChecked="{Binding IncludeLowercaseLetters, Mode=TwoWay}">Lowercase letters (a, b, c, ...)</CheckBox>
                <CheckBox Grid.Row="3" Grid.Column="0" Style="{StaticResource CommonKeyControlStyle}" IsChecked="{Binding IncludeDigits, Mode=TwoWay}">Digits (0, 1, 2, ...)</CheckBox>

                <CheckBox Grid.Row="1" Grid.Column="1" Style="{StaticResource CommonKeyControlStyle}" IsChecked="{Binding IncludeMinus, Mode=TwoWay}">Minus (-)</CheckBox>
                <CheckBox Grid.Row="2" Grid.Column="1" Style="{StaticResource CommonKeyControlStyle}" IsChecked="{Binding IncludeUnderscore, Mode=TwoWay}">Underscore (_)</CheckBox>
                <CheckBox Grid.Row="3" Grid.Column="1" Style="{StaticResource CommonKeyControlStyle}" IsChecked="{Binding IncludeSpace, Mode=TwoWay}">Space ( )</CheckBox>

                <CheckBox Grid.Row="1" Grid.Column="2" Style="{StaticResource CommonKeyControlStyle}" IsChecked="{Binding IncludeSpecialCharacters, Mode=TwoWay}">Special characters (!, $, %, &amp;, ...)</CheckBox>
                <CheckBox Grid.Row="2" Grid.Column="2" Style="{StaticResource CommonKeyControlStyle}" IsChecked="{Binding IncludeBrackets, Mode=TwoWay}">Brackets ([, ], {, }, (, ), &lt;, &gt;, ...)</CheckBox>
                <CheckBox Grid.Row="3" Grid.Column="2" Style="{StaticResource CommonKeyControlStyle}" IsChecked="{Binding IncludeHighAnsiCharacters, Mode=TwoWay}">High ANSI characters</CheckBox>

            </Grid>
            
            <StackPanel Grid.Row="2">
                <TextBlock Style="{StaticResource TextStyle}">Also include the following characters</TextBlock>
                <TextBox Style="{StaticResource TextBoxStyle}" Text="{Binding AdditionalCharacters}"
                         controls:ImmediateSourceUpdate.IsEnabled="True"
                         controls:ImmediateSourceUpdate.Source="{Binding AdditionalCharacters, Mode=TwoWay}"/>
            </StackPanel>
        </Grid>

        <Grid Grid.Row="2" Visibility="{Binding IsPatternGenerationEnabled, Converter={StaticResource VisibilityConverter}}" HorizontalAlignment="Center">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" MinWidth="600"></ColumnDefinition>
            </Grid.ColumnDefinitions>

            <TextBlock Grid.Row="0" Style="{StaticResource TextStyle}">Pattern</TextBlock>
            <TextBox Grid.Row="1" Style="{StaticResource TextBoxStyle}" Text="{Binding PasswordPattern}"
                     controls:ImmediateSourceUpdate.IsEnabled="True"
                     controls:ImmediateSourceUpdate.Source="{Binding PasswordPattern, Mode=TwoWay}"/>
            <CheckBox Grid.Row="2" Style="{StaticResource CommonKeyControlStyle}" IsChecked="{Binding IsRandomCharacterReorderingEnabled, Mode=TwoWay}">Randomly reorder characters</CheckBox>
        </Grid>
        
        <StackPanel Grid.Row="3" HorizontalAlignment="Center">
            <Button Style="{StaticResource ButtonStyle}" Command="{Binding GeneratePasswordCommand, Mode=TwoWay}">Generate Password</Button>
        </StackPanel>
        
        <StackPanel Grid.Row="4" MaxWidth="600">
            <TextBlock Style="{StaticResource TextStyle}">Generated Password</TextBlock>
            <TextBox Style="{StaticResource TextBoxStyle}" Text="{Binding GeneratedPassword}" IsReadOnly="True"></TextBox>
        </StackPanel>

        <StackPanel Grid.Row="5" Grid.ColumnSpan="3" Orientation="Horizontal" HorizontalAlignment="Center">
            <Button Style="{StaticResource ButtonStyle}" Command="{Binding SetPasswordCommand}">Set Password</Button>
            <Button Style="{StaticResource ButtonStyle}" Command="{Binding CancelCommand}">Cancel</Button>
        </StackPanel>
    </Grid>
</UserControl>
